package com.lagou.edu.intercepter;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 登录权限拦截器
 */
public class AuthIntercepter implements HandlerInterceptor {
    public static final String USERKEY="account";
    public static final String LOGINPAGE="/login.jsp";

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object attribute = request.getSession().getAttribute(USERKEY);
        if(attribute==null){
            System.out.println("用户未登录，跳转登录页面");
            response.sendRedirect(LOGINPAGE);
            return false;
        }
        return true;
    }
}